package com.daify.threadlearn.chapter01.queue;

import java.util.concurrent.ArrayBlockingQueue;

/**
 * 在构造时需要指定容量，内部基于数组的阻塞队列
 * @author daify
 * @date 2019-06-18 13:46
 **/
public class ArrayBlockingQueueTest {

    /**
     * 公平的队列
     */
    ArrayBlockingQueue nonfair = new ArrayBlockingQueue(10,false);

    /**
     * 非公平的队列
     */
    ArrayBlockingQueue fair = new ArrayBlockingQueue(10,true);

    /**
     * 锁的简单用法
     */
    public Thread getDefThread () {
        return new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    for (int i = 0; i < 10; i++) {
                        nonfair.add("属性:" + i);
                        System.out.println("放入的参数：" + "属性:" + i);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
}
